package com.hb.config;

import com.hb.service.SpitterService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.BurlapProxyFactoryBean;
import org.springframework.remoting.caucho.BurlapServiceExporter;

@Configuration
public class BurlapConfig {
    /**
     * 下面的 bean 定义展示了如何使用 BurlapServiceExporter 把 Spitter 服务导出为一个 Burlap 服务。
     * 这个 bean 与使用 Hessian 所对应 bean 的唯一区别在于 bean 的方法和导出类。配置 Burlap 服务和配置 Hessian 服务是一模一样的，
     * 这包括需要准备一个 URL 处理器和一个 DispatcherServlet。
     * @param service
     * @return
     */
    @Bean
    public BurlapServiceExporter burlapExporterSpitterService(SpitterService service) {
        BurlapServiceExporter exporter = new BurlapServiceExporter();
        exporter.setService(service);
        exporter.setServiceInterface(SpitterService.class);
        return exporter;
    }

    /**
     * 事实证明，把 Burlap 服务装配进客户端同样也没有太多新意。二者唯一的区别在于，我们要使用 BurlapProxyFactoryBean 来代替 HessianProxyFactoryBean
     * @return
     */
    @Bean
    public BurlapProxyFactoryBean spitterService() {
        BurlapProxyFactoryBean proxy = new BurlapProxyFactoryBean();
        proxy.setServiceUrl("http://localhost:8080/Spitter/spitter.service");
        proxy.setServiceInterface(SpitterService.class);
        return proxy;
    }
}
